SRCS := $(shell find -name "*.asm")
BINS := $(patsubst %.asm,%.bin,$(SRCS))
OUTPUT := test

all: $(OUTPUT).img

%.bin : %.asm
	nasm -f bin $^ -o $@ -l $@.lst

$(OUTPUT).img: $(BINS)
	dd if=./c09_mbr.bin of=$(OUTPUT).img bs=512 count=1
	dd if=./c09.bin of=$(OUTPUT).img bs=512 seek=100

clean:
	rm -rf *.bin *.lst *.img

qemu:
	qemu-system-i386 -drive file=$(OUTPUT).img

qemu-gdb:
	qemu-system-i386 -drive file=$(OUTPUT).img -S -s

gdb:
	gdb --tui \
		-ex 'target remote localhost:1234' \
		-ex 'set tdesc filename target.xml' \
		-ex 'tui new-layout reg2 regs 1 asm 0 status 0 cmd 1' \
		-ex 'layout reg2' \
		-ex 'set disassembly-flavor intel' \
		-ex 'display/10i $$cs*16+$$pc' \
		-ex 'focus cmd' \
		-ex 'break *0x7c00' \
		-ex 'continue'
